import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;

/**
 * Created by IntelliJ IDEA.<br>
 * User: maxim<br>
 * Date: Feb 21, 2010<br>
 * Time: 9:21:27 PM<br>
 * <p/>
 * <p/>
 * MobGraphBuilder - mobile graphics builder<br>
 * Copyright (C) 2010  Maxim Bondarenko<br>
 * <p/>
 * This program is free software: you can redistribute it and/or modify<br>
 * it under the terms of the GNU General Public License as published by<br>
 * the Free Software Foundation, either version 3 of the License, or<br>
 * (at your option) any later version.<br>
 * <br>
 * This program is distributed in the hope that it will be useful,<br>
 * but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the<br>
 * GNU General Public License for more details.<br>
 * <br>
 * You should have received a copy of the GNU General Public License<br>
 * along with this program.  If not, see <a href="http://www.gnu.org/licenses/">GNU Licenses</a><br>
 */

public class Line extends Canvas {
    private static float STEP = 0.1f;
    private static int X_START = 20;
    private static int Y_START = 150;

    public Line() {
        super();
    }

    public void paint(Graphics g) {
        g.setColor(0x0000ff);
        g.drawLine(20, 20, 90, 20);
        g.drawLine(40, 40, 140, 80);
        float x1 = 0;
        float x2 = STEP;
        float y1 = -(float) Math.sin(x1);
        float y2 = -(float) Math.sin(x2);
        g.drawString(String.valueOf(y2), 10, 50, Graphics.TOP | Graphics.LEFT);
        int x1Int = (int) (x1 * 20) + X_START;
        int x2Int = (int) (x2 * 20) + X_START;
        int y1Int = (int) (y1 * 20) + Y_START;
        int y2Int = (int) (y2 * 20) + Y_START;
        g.drawLine(x1Int, y1Int, x2Int, y2Int);
        for (int i = 0; i < 100; i++) {
            x1 = x2;
            x2 = x2 + STEP;
            y1 = -(float) Math.sin(x1);
            y2 = -(float) Math.sin(x2);
            x1Int = (int) (x1 * 20) + X_START;
            x2Int = (int) (x2 * 20) + X_START;
            y1Int = (int) (y1 * 20) + Y_START;
            y2Int = (int) (y2 * 20) + Y_START;
            System.out.println("y1 = "+ y1);
            System.out.println("y2 = "+ y2);
            g.drawLine(x1Int, y1Int, x2Int, y2Int);
        }
    }
}
